{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    {if condition="$id eq 0"}
    <div class="layui-form-bar">
        <h3 class="pb-3 tb-header">新增价格</h3>
    </div>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray">文印类型<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <select name="op" lay-verify="required" class="layui-input">
                        {volist name="op_types" id="vo"}
                        <option value="{$vo.name}" {eq name="$i" value="1"}selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </td>
            <td class="layui-td-gray">纸型<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <select name="paper" lay-verify="required" class="layui-input">
                        {volist name="paper_types" id="vo"}
                        <option value="{$vo.name}" {eq name="$i" value="1"}selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </td>
            <td class="layui-td-gray">单/双<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <select name="double" lay-verify="required" class="layui-input">
                        <option value="单" selected>单</option>
                        <option value="双">双</option>
                    </select>
                </div>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">价格</td>
            <td>
                <input type="number" name="price" lay-verify="required" placeholder="请输入价格" lay-reqText="价格" autocomplete="off" class="layui-input">
            </td>
        </tr>
    </table>
    {else/}
    <div class="layui-form-bar">
        <h3 class="pb-3">编辑价格</h3>
    </div>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray">文印类型<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$record.id}">
                    <select name="op" lay-verify="required" class="layui-input">
                        {volist name="op_types" id="vo"}
                        <option value="{$vo.name}" {eq name="$record.op" value="$vo.name" }selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </td>
            <td class="layui-td-gray">纸型<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <select name="paper" lay-verify="required" class="layui-input">
                        {volist name="paper_types" id="vo"}
                        <option value="{$vo.name}" {eq name="$record.paper" value="$vo.name" }selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </td>
            <td class="layui-td-gray">单/双<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <select name="double" lay-verify="required" class="layui-input">
                        <option value="单" {eq name="$record.double" value="单" }selected{/eq}>单</option>
                        <option value="双" {eq name="$record.double" value="双" }selected{/eq}>双</option>
                    </select>
                </div>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">价格</td>
            <td>
                <input type="number" name="price" lay-verify="required" value="{$record.price}" autocomplete="off" class="layui-input">
            </td>
        </tr>
    </table>
    {/if}
    <div class="py-3">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];

    function gouguInit() {
        let form = layui.form, tool = layui.tool;

        //监听提交
        form.on('submit(webform)', function (data) {
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    parent.layui.pageTable.reload();
                    setTimeout(function () {
                        parent.layui.tool.close();
                    }, 1000);
                }
            };
            tool.post("/admin/data/add_price", data.field, callback);
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->